package day15;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author xinxing
 * @date 2022/10/29 16:32
 */
public class SearchDay {

    private double rate = 0.5;

    public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";

    public static void main(String[] args) {
        getTime();
    }

    public static void getTime() {

        BigDecimal bigDecimal = BigDecimal.valueOf(24 / 0.5);
        int i = bigDecimal.intValue();

        Date date = strToDate("2022-09-10 00:00:00", DATE_FORMAT);

        for (int j = 0; j < i; j++) {
            date = getStartTime(date);
            System.out.println(dateToStr(date, DATE_FORMAT));
        }

    }

    public static Date strToDate(String dateStr, String DATE_FORMAT) {
        SimpleDateFormat myFormat = new SimpleDateFormat(DATE_FORMAT);
        try {
            return myFormat.parse(dateStr);
        } catch (ParseException e) {
            return null;
        }
    }

    public static String dateToStr(Date date, String DATE_FORMAT) {
        if (date == null) {
            return null;
        }
        SimpleDateFormat myFormat = new SimpleDateFormat(DATE_FORMAT);
        return myFormat.format(date);
    }


    public static Date getStartTime(Date date) {
        Calendar instance = Calendar.getInstance();
        instance.setTime(date);

        instance.add(Calendar.MINUTE, 30);
        return instance.getTime();
    }


}
